function filteredX = outlierFilter(X, a)
  % Outlier filter based on "0.2 Pearson's Second Skewness Criterion" found in 
  % Wuensch, Karl L. 2007 "Skewness, Kurtosis, and the Normal Curve"
  % http://core.ecu.edu/psyc/wuenschk/docs30/Skew-Kurt.doc
  %
  % Author: David Goldsmith, Wash. State Dept. of Ecology, dgol461@ecy.wa.gov
  % Release date: 9/15/2011

    if ~exist('a', 'var')
        a = 0.99;
    end
    Xskew = nanSkewness(X);
    [isskew, ~] = Xskew.TwoSidedFisherSkewnessTest(a);
    while ~isnan(isskew) && isskew 
        deviations = abs(Xskew.x - Xskew.meen);
        outlier = (deviations == max(deviations));
        Xskew = nanSkewness(Xskew.x(~outlier));
        [isskew, ~] = Xskew.TwoSidedFisherSkewnessTest(a);
    end
    filteredX = Xskew.x;
end